<template>
  <div>
    <div :id="mixtureId" class="mixture"></div>
  </div>
</template>
<script>
import MonthTable from "./energy/monthTable.vue";
let echarts = require("echarts");
export default {
  components: { MonthTable },
  props: {
    MixtureData: {
      type: Object,
      default: function () {
        return {};
      },
    },
    xAxisData: {
      type: Array,
      default: [],
    },
    text: {
      type: String,
      default: "",
    },
    mixtureId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  watch: {
    MixtureData: {
      handler() {
        this.initChart();
      },
      deep: true,
    },
  },
  mounted() {
    var chartDom = document.getElementById(this.mixtureId);
    this.myHisLevelChart = echarts.init(chartDom);
    this.$nextTick(() => {
      this.initChart();
    });
    window.addEventListener("resize", this.initChart, false);
  },
  created() {},
  methods: {
    initChart() {
      this.myHisLevelChart.resize();
      const colors = ["#5470C6", "#91CC75", "#EE6666"];
      var option = {
        color: colors,
        grid: {
          right: "20%",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
        },
        xAxis: [
          {
            type: "category",
            axisTick: {
              alignWithLabel: true,
            },
            data: this.xAxisData,
          },
        ],
        yAxis: [
          {
            type: "value",
            show: true,
            splitNumber: 10, //坐标轴的分割段数
            axisLabel: {
              fontSize: 14,
              color: "#333",
            },
            splitLine: {
              show: false, //是否显示分隔线。
            },
          },
          {
            type: "value",
            axisLabel: {
              fontSize: 14,
              color: "#333",
              formatter: "{value}",
            },
            splitLine: {
              show: false, //是否显示分隔线。
            },
          },
        ],
        legend: this.MixtureData.legend, //标记属性
        grid: this.MixtureData.grid, //绘图区调整
        series: this.MixtureData.series,
      };
      this.myHisLevelChart.setOption(option, true);
    },
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.initChart, false);
  },
};
//监听window窗口大小变化的事件
// window.onresize= function(){
//   echarts.resize()
// }
</script>
<style lang="scss" scoped>
.mixture {
  margin-top: 100px;
  width: 45%;
  height: 600px;
  border: 1px solid wheat;
  // height: 17rem;
}
</style>